// 导入数据库操作模块
const db = require('../db/index')

// 通过type查询科普内容
exports.queryScienceByType = (req, res) => {
    const data = req.body;
    const type = data.type;
    const sql = `select * 
                from popularization_science
                where type=?`;

    console.log(req.body);

    db.query(sql, [type], function (err, results) {
        if (err) {
            return res.send({ status: "查询出错", message: err.message })
        }
        return res.send(results);
    })
}

// 通过id查询科普内容
exports.queryScienceById = (req, res) => {
    const data = req.body;
    const id = data.id;
    const sql = `select * 
                from popularization_science
                where id=?`;

    console.log(req.body);

    db.query(sql, [id], function (err, results) {
        if (err) {
            return res.send({ status: "查询出错", message: err.message })
        }
        return res.send(results);
    })
}